package com.tgky.ybzb.config.exception;

import com.tgky.ybzb.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理器
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(YBGLBaesException.class)
    public Result hjpgBaesExceptionHandler(YBGLBaesException e) {
        log.error("YBGLBaesException: " + e.getMessage(), e);
        return Result.error(e.getCode(), e.getMessage());
    }


    @ExceptionHandler(RuntimeException.class)
    public Result runtimeExceptionHandler(RuntimeException e) {
        log.error("ServerException", e);
        return Result.error("系统异常");
    }
}
